package com.snbc.smcp.pipeline;

import com.github.artbits.quickio.api.Collection;
import com.github.artbits.quickio.api.DB;
import com.github.artbits.quickio.api.KV;
import com.github.artbits.quickio.core.Config;
import com.github.artbits.quickio.core.QuickIO;
import com.github.artbits.quickio.struct.Document;

import java.util.List;

/**
 * 类描述:   https://github.com/artbits/quickio .
 *
 * @author xuping
 * 创建时间:  [2023/10/16 19:21]
 */
public class QuickioTest3 {

    public static void main(String[] args) {

        Config config =Config.of(config1 -> {
            config1.path("/Users/pingxu/temp/data/");
            config1.name("zuaa4");
            config1.cache(10000L);
        });

        DB db = QuickIO.usingDB(config);
        Collection<ZuaaUser> collection =    db.collection(ZuaaUser.class);
        long startTime = System.currentTimeMillis();
//        for (int i = 0; i < 1000000; i++) {
//            ZuaaUser zuaaUser = new ZuaaUser();
//             zuaaUser.setName("zuaa-"+i);
//             zuaaUser.setPsw("zuaa-"+i);
//            collection.save(zuaaUser);
//        }
        System.out.println("代码执行时间: " + (System.currentTimeMillis()-startTime) + " 毫秒");
        startTime = System.currentTimeMillis();
        List<ZuaaUser> zuaaUser1 = collection.find(d -> "zuaa-10021".equals(d.getName()));
        System.out.println(zuaaUser1);
        for (ZuaaUser zuaaUser : zuaaUser1) {
             zuaaUser.printJson() ;
        }
        System.out.println("代码执行时间: " + (System.currentTimeMillis()-startTime) + " 毫秒");
        startTime = System.currentTimeMillis();
         ZuaaUser  zuaaUser2 = collection.findWithIndex(d -> d.index("name", "zuaa-1111"));
        System.out.println(zuaaUser2);

        System.out.println("代码执行时间: " + (System.currentTimeMillis()-startTime) + " 毫秒");
        db.close();
    }
}
